# 设置控制台编码为UTF-8
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

# 测试自动化脚本 (PowerShell版本)

Write-Host "开始自动化测试..." -ForegroundColor Green -BackgroundColor Black

# 1. 安装依赖
Write-Host "1. 安装依赖..." -ForegroundColor Yellow
Set-Location "migration\frontend"
npm install

if ($LASTEXITCODE -ne 0) {
  Write-Host "错误: 依赖安装失败，错误代码: $LASTEXITCODE" -ForegroundColor Red
  exit 1
}

Write-Host "依赖安装成功" -ForegroundColor Green

# 2. 运行单元测试
Write-Host "2. 运行单元测试..." -ForegroundColor Yellow
npm run test

if ($LASTEXITCODE -ne 0) {
  Write-Host "错误: 单元测试失败，错误代码: $LASTEXITCODE" -ForegroundColor Red
  exit 1
}

Write-Host "单元测试成功" -ForegroundColor Green

# 3. 生成测试覆盖率报告
Write-Host "3. 生成测试覆盖率报告..." -ForegroundColor Yellow
npm run test:coverage

if ($LASTEXITCODE -ne 0) {
  Write-Host "错误: 测试覆盖率报告生成失败，错误代码: $LASTEXITCODE" -ForegroundColor Red
  exit 1
}

Write-Host "测试覆盖率报告生成成功" -ForegroundColor Green

Write-Host "自动化测试完成!" -ForegroundColor Green